<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Access-Control-Allow-Origin" content="*" />
    <title>reactlesson11</title>

    <script src="../build/react.development.js"></script>
    <script src="../build/react-dom.development.js"></script>
    <script src="../build/babel.min.js"></script>
    <script src="../build/jquery-3.3.1.min.js"></script>
</head>
<body>
<div id="example"></div>

<script type="text/babel">
    class UserGist extends React.Component {
        constructor(props) {
            super(props);
            this.state = {userName: '', lastGistUrl: ''};
        }

        componentDidMount() {
            $.get(this.props.source, function (result) {
                var lastGist = result[0];
                this.setState({
                    username: lastGist.owner.login,
                    lastGistUrl: lastGist.html_url
                });
            }.bind(this));
        }

        render() {
            return (
                    <div>
                        {this.state.username}'s last gist is <a href={this.state.lastGistUrl}>here</a>.
                    </div>
            );
        }
    }

    ReactDOM.render(<UserGist source="https://api.github.com/users/yuanbp/gists"/>, document.getElementById("example"));
</script>
</body>
</html>